package com.paireach.szwolaiyun.fragmentall;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.paireach.szwolaiyun.R;
import com.paireach.szwolaiyun.newFragment.BarCoderFragment;

/**
 * 装货结束
 * Created by Administrator on 2016/7/4.
 */
public class FinishLoadingFragment extends BarCoderFragment implements BarCoderFragment.OnBarCodeGenerateListener {

    public static final String TAG = "FinishLoadingFragment";
    private View view;
    private TextView bar_code_num;
    private ImageView imageView;

    private String orderNo;

    public static final FinishLoadingFragment getInstance(String orderNo) {
        FinishLoadingFragment factoryQueueScanBarCodeFragment = new FinishLoadingFragment();
        Bundle bundle = new Bundle();
        bundle.putString("orderNo", orderNo);
        factoryQueueScanBarCodeFragment.setArguments(bundle);
        return factoryQueueScanBarCodeFragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle bundle = getArguments();
        if (bundle != null) {
            orderNo = bundle.getString("orderNo");
        }
        setOnBarCodeGeneratedListener(this);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_finish_loading, null);
        view.findViewById(R.id.layout_top_back).setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View view) {
                getActivity().finish();
            }
        });
        ((TextView) view.findViewById(R.id.layout_top_change)).setText("装货完成");
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView();
        startGenerateBarCode(orderNo);
    }

    @Override
    public void onDestroy() {
        try {
            imageView.setImageBitmap(null);
        } catch (Exception e) {
        }
        super.onDestroy();
    }

    private void initView() {
        bar_code_num = (TextView) view.findViewById(R.id.bar_code_num);
        imageView = (ImageView) view.findViewById(R.id.bar_code_img);
        bar_code_num.setText(orderNo);
    }

    @Override
    public void onBarCodeGenerated(Bitmap bitmap) {
        imageView.setImageBitmap(bitmap);
    }

}
